package client;
/**
 * 
 * Copyright (C) 2011 Cody Stoutenburg . All rights reserved.
 *
 *       This program is free software; you can redistribute it and/or
 *       modify it under the terms of the GNU Lesser General Public License
 *       as published by the Free Software Foundation; either version 2.1
 *       of the License, or (at your option) any later version.
 *
 *       This program is distributed in the hope that it will be useful,
 *       but WITHOUT ANY WARRANTY; without even the implied warranty of
 *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *       GNU Lesser General Public License for more details.
 *
 *       You should have received a copy of the GNU Lesser General Public License
 *       along with this program; if not, write to the Free Software
 *       Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
 * 
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.rmi.RMISecurityManager;

/**
 * @author Cody Stoutenburg
 * 
 */
public class MainClient2 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));

		try {
			// Set the security depending on the file
			System.out.println("-------------------------------------");
			System.out.println("Donnez le path du fichier security:");
			String path = reader.readLine();// "C:/Users/ligarnes/workspace/TravauxCours/ift605-tp2-server/security.txt";
			System.setProperty("java.security.policy", path);
			System.out.println(System.getProperty("java.security.policy"));

			// Create and install a security manager
			if (System.getSecurityManager() == null) {
				System.setSecurityManager(new RMISecurityManager());
			}

			// Set the web server where to dowload source
			System.out.println("-------------------------------------");
			System.out
					.println("Donnez l'adresse du serveur web des sources: (you can use http://www.alteiar.net/ift605/client2/)");
			String webAdress = reader.readLine();// "http://www.alteiar.net/ift605/client/"
			System.setProperty("java.rmi.server.codebase", webAdress);
			System.out.println(System.getProperty("java.rmi.server.codebase"));

			System.out.println("-------------------------------------");
			System.out.println("Information Registry");
			System.out.println("Donnez l'adresse ip du registry:");
			String adressIp = reader.readLine();
			System.out.println("Donnez le port du registry:");
			String port = reader.readLine();
			System.out.println("-------------------------------------");

			System.out.println("choisir le nom du calculateur");
			String name = reader.readLine();

			SimpleChatClient chat = new SimpleChatClient();
			chat.connect(adressIp, port, name);

			boolean stop = false;
			while (!stop) {
				System.out.println("taper sur une touche pour quitter");
				try {
					System.in.read();
					stop = true;
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
